package com.power.algorithm;

import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: jiangnan
 * @time: 2021/6/18 2:22 下午
 */
public class Solution242 {
    public boolean isAnagram(String s, String t) {

        char chs[] = s.toCharArray();
        char cht[] = t.toCharArray();
        HashMap<Character, Integer> hashMap = new HashMap();
        HashMap<Character, Integer> hashMap1 = new HashMap<>();
        if (chs.length != cht.length) {
            return false;
        }

        for (int i = 0; i < chs.length; i++) {
            hashMap.put(chs[i], hashMap.getOrDefault(chs[i], 0) + 1);
        }

        for (int i = 0; i < cht.length; i++) {
            hashMap1.put(cht[i], hashMap1.getOrDefault(cht[i], 0) + 1);
        }

        for (Map.Entry entry : hashMap.entrySet()) {
            if (entry.getValue() != hashMap1.get(entry.getKey())) {
                return false;
            }
        }
        return true;
    }


    public static void main(String[] args) {

    }
}
